﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using HNG.LIB.Controls;
using HNG.Portal.BLL;
using HNG.Portal.DAL;
using HNG.Portal.DAL.EntityClasses;
using HNG.Portal.DAL.FactoryClasses;
using HNG.Portal.DAL.HelperClasses;
using SD.LLBLGen.Pro.ORMSupportClasses;
using System.Web.UI.HtmlControls;
using System.Data;
using System.IO;
using HNG.LIB.Common;
public partial class AdminPortal_Controls_Account_ChangePass : System.Web.UI.UserControl
{
    TblThanhVienManager _TblThanhVienManager = new TblThanhVienManager();
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            hidID.Value = Request.QueryString["id"].Trim();
            txtID.Text = hidID.Value;
            if (Session[Constants.SessionUserId] != null)
            {
                hidCurrentID.Value = Session[Constants.SessionUserId].ToString();
            }

            if (hidID.Value.Equals(hidCurrentID.Value) == false)
            {
                txtPassNew.Enabled = txtRePassNew.Enabled = false;
                lblThongBao.Visible = true;

                if (FunctionExtend.IsAdmin(Convert.ToInt32(hidCurrentID.Value)))
                {
                    txtPassNew.Enabled = txtRePassNew.Enabled = true;
                    lblThongBao.Visible = false;
                }
            }
        }
    }

    private void SavePass()
    {
        if (hidID.Value != "")
        {
            TblThanhVienEntity _TblThanhVienEntity = _TblThanhVienManager.SelectOne(Convert.ToInt32(hidID.Value));
            if (_TblThanhVienEntity != null)
            {
                _TblThanhVienEntity.MatKhau = HNG.LIB.Localization.LocalizationUtils.MaHoaMatKhau(txtPassNew.Text);
                _TblThanhVienManager.Update(_TblThanhVienEntity);
            }
        }
    }
    protected void btnSave_Click(object sender, EventArgs e)
    {
        if (txtPassNew.Text != "" && txtRePassNew.Text != "" && txtPassNew.Text.Equals(txtRePassNew.Text))
        {
            SavePass();
            Response.Redirect(ResolveUrl("~/AdminPortal/Pages/UserList.aspx"));
        }
        else
            ScriptManager.RegisterStartupScript(this, this.GetType(), "redirectMe", "showMessageSlide('Lỗi', 'xác nhận mật khẩu không đúng !');", true);
    }

    protected void btnBack_Click(object sender, EventArgs e)
    {
        Response.Redirect(ResolveUrl("~/AdminPortal/Pages/UserList.aspx"));
    }
}